<template>
  <div class="loginForm">
    <div class="container">
      <el-form
          label-width="6px"
          :model="formLabelAlign"
          style="max-width: 800px"
      >

        <el-form-item label="学号" :label-position="itemLabelPosition">
          <el-input v-model="formLabelAlign.stuNum">
            <template #suffix>
              <el-icon>
                <UserFilled/>
              </el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="密码" :label-position="itemLabelPosition">
          <el-input
              v-model="formLabelAlign.password"
              type="password"
              placeholder="请输入密码"
              show-password
          >
            <template #suffix>
              <el-icon><Lock /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="onLogin" type="primary">登录</el-button>
          <el-button @click="onRegister">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {reactive, ref} from 'vue'

import type {FormItemProps} from 'element-plus'
import {Lock, UserFilled} from "@element-plus/icons-vue";
import {useStore} from "vuex";
import {useRouter} from "vue-router";
import { ElNotification } from 'element-plus'

const store=useStore()
const router = useRouter()

const itemLabelPosition = ref<FormItemProps['labelPosition']>('top')
const formLabelAlign = reactive({
  stuNum: '',
  password: '',
})
// 处理登录事件
const onLogin=()=>{
  store.dispatch("login/login",formLabelAlign)
  ElNotification({
    title: '登录成功',
    message: '即将前往主页',
    type: 'success',
  })
}
// 处理注册事件
const onRegister=()=>{
  router.push({name:'register'})
}


</script>

<style scoped>
.loginForm{

}
.container{
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 1vh;
}
.el-form {
  border: 2px;
}

.el-form-item {
  min-width: 500px;
}
</style>
